package com.iniapp.app.web.action;


import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.inibb.app.constant.GenericCodeConstant;
import com.inibb.app.service.IGoodsService;
import com.inibb.app.service.INoteService;
import com.inibb.app.service.admin.IGenericCodeService;
import com.inibb.app.vo.GenericCodeVO;
import com.inibb.app.vo.GoodsSC;
import com.inibb.app.vo.GoodsVO;
import com.inibb.app.vo.NoteSC;
import com.inibb.app.vo.NoteVO;

@Controller("mainCtrl")
@Scope("session")//page
public class MainCtrl extends BaseCtrl  implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private IGenericCodeService genericCodeService;
	@Autowired
	private IGoodsService goodsService;
	@Autowired
	private INoteService noteService;
	
	private List<NoteVO> noteList;
	List<GoodsVO> goodsList;
	private List<GoodsVO> goodsListHot;

	@PostConstruct
	public void init(){
		//get note 100026
		GenericCodeVO gg = genericCodeService.searchCodeByTypeAndCode(GenericCodeConstant.CODE_TYPE_NOTE,GenericCodeConstant.CODE_TYPE_NOTE_GG);
		if(gg!=null){
			NoteSC paginationCriteria = new NoteSC();
			paginationCriteria.setNoteType(gg.getCodeId().toString());
			paginationCriteria.setStartRow(0);
			paginationCriteria.setPageSize(6);
			noteList = noteService.searchPageNotes(paginationCriteria);
			for(NoteVO vo:noteList){
				vo.setTitle(StringUtils.substring(vo.getTitle(), 0, 15));
			}
		}

		GoodsSC paginationCriteria2 = new GoodsSC();
		
		//get new products
		paginationCriteria2.setStartRow(0);
		paginationCriteria2.setPageSize(6);
		paginationCriteria2.setNewArrival(GenericCodeConstant.IND_YES);
		goodsList = goodsService.searchGoods(paginationCriteria2);
		
		//get hot products
		GoodsSC paginationCriteriaHot = new GoodsSC();
		paginationCriteriaHot.setStartRow(0);
		paginationCriteriaHot.setPageSize(6);
		paginationCriteriaHot.setHot(GenericCodeConstant.IND_YES);
		goodsListHot = goodsService.searchGoods(paginationCriteriaHot);
	}

	public List<NoteVO> getNoteList() {
		return noteList;
	}

	public void setNoteList(List<NoteVO> noteList) {
		this.noteList = noteList;
	}

	public List<GoodsVO> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<GoodsVO> goodsList) {
		this.goodsList = goodsList;
	}

	public List<GoodsVO> getGoodsListHot() {
		return goodsListHot;
	}

	public void setGoodsListHot(List<GoodsVO> goodsListHot) {
		this.goodsListHot = goodsListHot;
	}
	
	
}
